package com.liuqi.base.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.liuqi.base.bean.dto.ModelTypeDTO;
import com.liuqi.base.bean.query.ModelTypeQuery;
import com.liuqi.base.bean.req.ModelTypeAddReq;
import com.liuqi.base.bean.req.ModelTypeUpdateReq;
import com.liuqi.base.service.ModelTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模型分类控制器 
 * @author Coder Generator 2025-03-14 12:16:29 
 **/
@RestController
@RequestMapping("/base/model-type")
@Slf4j
@Tag(name = "模型分类控制器")
public class ModelTypeController {
    @Autowired
    private ModelTypeService service;

    @PostMapping("add")
    @Operation(summary = "新增")
    public void add(@RequestBody @Validated ModelTypeAddReq req) {
        ModelTypeDTO dto = new ModelTypeDTO();
        BeanUtils.copyProperties(req, dto);
        service.insert(dto);
    }

    @PutMapping("update")
    @Operation(summary = "更新")
    public void update(@RequestBody @Validated ModelTypeUpdateReq req) {
        ModelTypeDTO dto = new ModelTypeDTO();
        BeanUtils.copyProperties(req, dto);
        service.update(dto);
    }

    @DeleteMapping("delete/{id}")
    @Operation(summary = "删除")
    public void delete(@PathVariable("id") String id) {
        service.delete(id);
    }

    @GetMapping("detail/{id}")
    @Operation(summary = "根据id查找记录")
    public ModelTypeDTO findById(@PathVariable("id") String id) {
        return service.findById(id).orElse(null);
    }

    @PostMapping("page-query")
    @Operation(summary = "查询-分页")
    public IPage<ModelTypeDTO> pageQuery(@RequestBody ModelTypeQuery query) {
        return service.pageQuery(query);
    }

    @PostMapping("query")
    @Operation(summary = "查询-不分页")
    public List<ModelTypeDTO> query(@RequestBody ModelTypeQuery query) {
        return service.query(query);
    }

    @GetMapping("tree")
    public List<ModelTypeDTO> tree() {
        return service.tree();
    }
}